<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>浮动去空格</title>
    <style>
        button { margin: 0; }
        p { clear: both; }
    </style>
</head>

<body>
<button>按钮1</button>&nbsp;
<button>按钮2</button>&nbsp;
<button>按钮3</button>&nbsp;
<button>按钮4</button>&nbsp;
<p><input type="button" id="trigger" value="点击按钮浮动"></p>
<script>
  var trigger = document.getElementById("trigger"),
    buttons = document.getElementsByTagName("button");

  var length = buttons.length;

  if (trigger && length > 0) {
    trigger.onclick = function() {
      for (var index = 0; index < length; index += 1) {
        //在 Internet Explorer 8 和更老的IE当中，要使用styleFloat属性
        buttons[index].style["cssFloat" in trigger.style? "cssFloat": "styleFloat"] = "left";
      }
    };
  }
</script>
</body>
</html>
